CLASS zcl_mes_if_001 DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.

    CLASS-METHODS: post IMPORTING request TYPE string EXPORTING response TYPE string.
  PROTECTED SECTION.
  PRIVATE SECTION.

ENDCLASS.



CLASS ZCL_MES_IF_001 IMPLEMENTATION.


  METHOD post .

    DATA:BEGIN OF ls_tab,
           status TYPE c LENGTH 20,
         END OF ls_tab.

    DATA:BEGIN OF ls_return,
           matnr TYPE c LENGTH 40,
           meins TYPE c LENGTH 4,
         END OF ls_return.
    DATA:lt_return LIKE TABLE OF ls_return.
    DATA:lt_temp LIKE TABLE OF ls_return.


    /ui2/cl_json=>deserialize(
        EXPORTING json = request
                  pretty_name = /ui2/cl_json=>pretty_mode-low_case
        CHANGING data = ls_tab
        ).


    IF ls_tab-status = 'S'.
      SELECT
      product AS matnr ,
      baseunit AS meins
      FROM i_product
      INTO TABLE @lt_temp.

      DO 200 TIMES.
        APPEND LINES OF lt_temp TO lt_return.
      ENDDO.
      response = /ui2/cl_json=>serialize( lt_return ).
    ELSE.
      response = 'Error'.
    ENDIF.


  ENDMETHOD.
ENDCLASS.
